package com.expense.app.admin.controller;

import com.expense.app.admin.model.params.student.StudentExportParam;
import com.expense.app.admin.model.params.student.StudentImportParam;
import com.expense.common.model.Student;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import javax.validation.constraints.Min;
import com.expense.common.util.Result;
import com.expense.app.admin.services.StudentServ;
import com.expense.app.admin.model.params.student.StudentParam;
import com.expense.app.admin.model.params.student.StudentListParam;

import java.util.List;

/*
*
* gen controller 2019-09-06
*/
@Validated
@RestController
@RequestMapping("/student")
public class StudentCtrl {

    @Autowired
    StudentServ studentServ;

    @PostMapping("/import")
    public Result importExcel(@RequestBody StudentImportParam param) {
        return Result.success(studentServ.importExcel(param));
    }

    @PostMapping("/saveList")
    public Result saveList(@RequestBody StudentParam param){
        return Result.success(studentServ.saveList(param));
    }

    @PostMapping("/findListByParam")
    public Result findListByParam(@RequestBody StudentExportParam param){
        return Result.success(studentServ.findListByParam(param));
    }

    @RequestMapping(value = "/findList",method = RequestMethod.GET)
    public Result findList(@Validated StudentListParam params) {
        return Result.success(studentServ.findList(params));
    }

    @GetMapping(value = "/{id}")
    public Result findDetail (@PathVariable @Min(1) Long id) {
        return Result.success(studentServ.findDetail(id));
    }

    /*@PostMapping(value = "")
    public Result saveOne(@Validated @RequestBody StudentParam param) {
        return Result.success(studentServ.saveOne(param));
    }*/

    /*@PutMapping(value = "")
    public Result update(@Validated @RequestBody StudentParam param) {
        return Result.success(studentServ.saveOne(param));
    }*/

    @DeleteMapping(value = "/{id}")
    public Result deleteOne(@PathVariable @Min(1) Long id) {
        return Result.success(studentServ.deleteOne(id));
    }
}
